<?php

/**
 * This is the model class for table "tagok".
 *
 * The followings are the available columns in table 'tagok':
 * @property integer $id
 * @property string $name
 * @property string $text
 * @property integer $active
 */
class Member extends CActiveRecord
{
    public $image;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Member the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tagok';
	}
    
    public function behaviors() {
		return array(
			'imageBehavior' => array(
				'class' => 'ImageARBehavior',
				'attribute' => 'image', // this must exist
				'extension' => 'png, jpg', // possible extensions, comma separated
				'prefix' => 'member_',
				'relativeWebRootFolder' => 'images/members', // this folder must exist
				
				# 'forceExt' => png, // this is the default, every saved image will be a png one.
				# Set to null if you want to keep the original format
				
				//'useImageMagick' => '/usr/bin', # I want to use imagemagick instead of GD, and
				# it is located in /usr/bin on my computer.
				
				// this will define formats for the image.
				// The format 'normal' always exist. This is the default format, by default no
				// suffix or no processing is enabled.
				'formats' => array(	
                    'thumb' => array(
						'suffix' => '_thumb',
						'process' => array('resize' => array(60, 60)),
					),			
					// create a large one (in fact, no resize is applied)
					'large' => array(						
                        'process' => array('resize' => array(1000, 1000)),
					),
					// and override the default :
					'normal' => array(
                        'suffix' => '_mid',
						'process' => array('resize' => array(200, 200)),
					),
				),
				
				'defaultName' => 'default', // when no file is associated, this one is used by getFileUrl
				// defaultName need to exist in the relativeWebRootFolder path, and prefixed by prefix,
				// and with one of the possible extensions. if multiple formats are used, a default file must exist
				// for each format. Name is constructed like this :
				//     {prefix}{name of the default file}{suffix}{one of the extension}
			)
		);
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, text, active', 'required'),
			array('name', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, text, active', 'safe', 'on'=>'search'),
             array('image', 'file', 'types' => 'png, jpg, jpeg', 'allowEmpty' => true), // behavior
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Név',
			'text' => 'Szöveg',
			'active' => 'Aktív',
            'photo' => 'Fotó',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('text',$this->text,true);
		$criteria->compare('active',$this->active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}